/**
 * <pre>
 * Title: 		MillonSecondIterator.java
 * Project: 	AnteAgent
 * Type:		com.hengpeng.anteagent.scheduling.iterators.MillonSecondIterator
 * Author:		linriqing
 * Create:	 	2007-1-9 9:15:53
 * Copyright: 	Copyright (c) 2007
 * Company:		
 * <pre>
 */
package com.hengpeng.common.scheduling.iterators;

import java.util.Calendar;
import java.util.Date;

import org.tiling.scheduling.ScheduleIterator;

/**
 * <pre>
 * 按毫秒循环的迭代器
 * </pre>
 * @author linriqing
 * @version 1.0, 2007-1-9
 */
public class MillonSecondIterator implements ScheduleIterator
{
	private int interval;

	private long timeinMillonSeconds;

	/**
	 * 构造函数
	 * @param interval 迭代的毫秒数
	 */
	public MillonSecondIterator(int interval)
	{
		this.interval = interval;
		this.timeinMillonSeconds = new Date().getTime();
	}

	public Date next()
	{
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(timeinMillonSeconds);
		do
		{
			calendar.add(Calendar.MILLISECOND, interval);
		}
		while (calendar.getTimeInMillis() < System.currentTimeMillis());
		this.timeinMillonSeconds = calendar.getTimeInMillis();
		return calendar.getTime();
	}

}
